package edu.nf.placeorder.service;

import edu.nf.placeorder.common.config.RabbitConfig;
import edu.nf.placeorder.entity.Order;
import edu.nf.placeorder.mapper.GoodsMapper;
import edu.nf.placeorder.mapper.OrderMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author wangl
 * @date 2025/10/16
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class OrderConsumer {

    private final OrderMapper orderMapper;
    private final GoodsMapper goodsMapper;
    private final RedisTemplate<String, Object> redisTemplate;

    /**
     * 如果用户在指定的时间内没有完成支付则修改订单状态为失效，
     * 并且要回填redis库存
     * 如果用户完成支付则修改订单状态为已支付，并且扣减数据库的库存
     * 订单状态：
     * 0：未支付
     * 1：已支付
     * 2：已失效
     * @param orderId
     */
    @RabbitListener(queues = RabbitConfig.DELAY_QUEUE)
    public void receive(int orderId) {
        //1.查询订单
        //2.如果订单状态为0，则改为2(失效状态)并回填Redis库存,
        //否则同步扣减数据库库存
    }
}